package com.swmaestro.twar.model;

import org.joda.time.DateTime;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.swmaestro.twar.Utils;


public class Feed {
	public String name;
	public DateTime date;//->Date or DateTime
	public String content;
	
	public Integer position;
	public Integer num_of_ups;
	public Integer num_of_downs;
	
	/*
	private static final int INDEX_NO = 0;
	private static final int INDEX_ISSUE = 1;
	private static final int INDEX_POSITION = 2;
	private static final int INDEX_NAME = 3;
	private static final int INDEX_EMAIL = 4;
	private static final int INDEX_MEMO = 5;
	private static final int INDEX_RECOMMEND = 6;
	private static final int INDEX_OPPOSITE = 7;
	private static final int INDEX_DATE = 8;
	private static final int INDEX_IP = 9;
	
	private static final int _INDEX_NAME = INDEX_NAME;
	private static final int _INDEX_DATE = INDEX_DATE;
	private static final int _INDEX_CONTENT = INDEX_MEMO;
	private static final int _INDEX_POSITION = INDEX_POSITION;
	private static final int _INDEX_NUM_OF_UPS = INDEX_RECOMMEND;
	private static final int _INDEX_NUM_OF_DOWNS = INDEX_OPPOSITE;
	*/
	
	private static final String _KEY_NAME = "name";
	private static final String _KEY_DATE = "date";
	private static final String _KEY_CONTENT = "memo";
	private static final String _KEY_POSITION = "position";
	private static final String _KEY_NUM_OF_UPS = "recommend";
	private static final String _KEY_NUM_OF_DOWNS = "opposite";
	
	public Feed(JSONObject jo) throws JSONException {
		/*
		this.name = ja.getString(_INDEX_NAME);
		this.date = Utils.convertString2DateTime(ja.getString(_INDEX_DATE));
		this.content = ja.getString(_INDEX_CONTENT);
		this.position = Integer.parseInt(ja.getString(_INDEX_POSITION));
		this.num_of_ups = Integer.parseInt(ja.getString(_INDEX_NUM_OF_UPS));
		this.num_of_downs = Integer.parseInt(ja.getString(_INDEX_NUM_OF_DOWNS));
		*/
		this.name = jo.getString(_KEY_NAME);
//		Log.d("test", this.name);
		this.date = Utils.convertString2DateTime(jo.getString(_KEY_DATE));
		this.content = jo.getString(_KEY_CONTENT);
		this.position = Integer.parseInt(jo.getString(_KEY_POSITION));
		this.num_of_ups = Integer.parseInt(jo.getString(_KEY_NUM_OF_UPS));
		this.num_of_downs = Integer.parseInt(jo.getString(_KEY_NUM_OF_DOWNS));
	}
	
	
	//for test purpose
	public Feed(String name, DateTime date, String content, Integer position, Integer num_of_ups, Integer num_of_downs) {
		this.name = name;
		this.date = date;
		this.content = content;
		this.position = position;
		this.num_of_ups = num_of_ups;
		this.num_of_downs = num_of_downs;
	}
}
